#include <iostream>
#include <cstdio>
using namespace std;
long long b, p, k;
long long power(long long y, long long x) {
if (x == 0 ) return 1 % k ; 
long long s = power (y , x / 2 ) ;
if (x % 2 == 0 ) return s * s % k ; 
return s * s % k * y % k ; }
int main () {
scanf ("%lld%lld%lld", &b, &p, &k);
printf("%lld^%lld mod %lld=%lld", b, p, k, power (b%k,p));
return 0;
}